//  K部分用票人信息
import axios from './../utils/http';


function getFromField(activityId, ticketTypeId) {
  return new Promise((resolve) => {
    let subData = {
      activityId: activityId,
      ticketTypeId: ticketTypeId
    };
    let resolveData = {
      success: false,
      errorMsg: '',
      result: []
    };
    axios.post('temp/queryTempletByTicketTypeId', subData).then(resData => {
      if (resData.success) {
        if (resData.result && resData.result.vnote1) {
          resolveData.success = true;
          resolveData.result = JSON.parse(resData.result.vnote1);
        } else {
          resolveData.errorMsg = '未获取到表单数据！';
        }
      } else {
        resolveData.errorMsg = resData.errorMsg || '数据获取失败！';
      }
      resolve(resolveData);
    }, err => {
      resolveData.errorMsg = '服务器出小差了！';
      resolve(resolveData);
    });
  });
}

// 得到用票人保存的报名表单信息
function getTicketInfo(id) {
  return new Promise((resolve) => {
    let subData = {
      id: id,
    };
    let resolveData = {
      success: false,
      errorMsg: '',
      result: []
    };
    axios.post('ticketPurchaseMob/queryTicketPsnLinkerByPsnId', subData).then(resData => {
      if (resData.success) {
        resolveData.success = true;
        resolveData.result = resData.result;
      } else {
        resolveData.errorMsg = resData.errorMsg || '数据获取失败！';
      }
      resolve(resolveData);
    }, err => {
      resolveData.errorMsg = '服务器出小差了！';
      resolve(resolveData);
    });
  });
}

// 新增用票人的报名表单信息
function addTicketPsnDoc(formJson) {
  return new Promise((resolve) => {
    let subData = {
      formJson: formJson,
    };
    let resolveData = {
      success: false,
      errorMsg: '',
      result: []
    };
    axios.post('ticketPurchaseMob/addTicketPsnDoc', subData).then(resData => {
      if (resData.success) {
        resolveData.success = true;
        resolveData.result = resData.result;
      } else {
        resolveData.errorMsg = resData.errorMsg || '请重试！';
      }
      resolve(resolveData);
    }, err => {
      resolveData.errorMsg = '服务器出小差了！';
      resolve(resolveData);
    });
  });
}

// 更新用票人保存的报名表单信息
function upDataTicketPsnDoc(formJson) {
  return new Promise((resolve) => {
    let subData = formJson;
    let resolveData = {
      success: false,
      errorMsg: '',
      result: []
    };
    axios.post('ticketPurchaseMob/updateTicketPsnDoc', subData).then(resData => {
      if (resData.success) {
        resolveData.success = true;
        resolveData.result = resData.result;
      } else {
        resolveData.errorMsg = resData.errorMsg || '请重试！';
      }
      resolve(resolveData);
    }, err => {
      resolveData.errorMsg = '服务器出小差了！';
      resolve(resolveData);
    });
  });
}

export {
  getFromField,
  getTicketInfo,
  addTicketPsnDoc,
  upDataTicketPsnDoc
};
